//
//  Country.m
//  Risiko
//
//  Created by Murgia Giovanni on 06/07/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Country.h"


@implementation Country
-(id) initWithName:(NSString*) aName{
	[super init];
	name = aName;
	nearCountries = [[NSMutableSet alloc]init];
	return self;
}
-(Boolean) isNearTo:(Country*) anotherCountry{
	for (NSString * k in nearCountries)
		if ([k isEqualToString:[anotherCountry getName]])
			return TRUE;
	return FALSE;
}
-(void) addNearCountry:(Country*) toAdd{
	[nearCountries addObject:[toAdd getName]];
}
-(NSString*) getName{
	return name;
}
-(void) setContinent:(Continent*) toSet{
	continentName = [toSet getName];
}
-(NSSet*) getNearCountries {
	return nearCountries;
}
- (void) encodeWithCoder:(NSCoder*) coder
{
	[coder encodeObject:name forKey:@"name"];
	[coder encodeObject:continentName forKey:@"continent"];
	[coder encodeObject:nearCountries forKey:@"nearCountries"];
}


- (id) initWithCoder:(NSCoder*) coder
{
	[self init];
	name = [coder decodeObjectForKey:@"name"];
	[name retain];
	continentName = [coder decodeObjectForKey:@"continent"];
	[continentName retain];
	nearCountries = [coder decodeObjectForKey:@"nearCountries"];
	[nearCountries retain];
	return self;
}
-(NSString*) description{
	return [[NSString alloc]initWithFormat:@"name:%@\n continent:%@\n countries%@\n",name,continentName,nearCountries];
}
@end
